﻿using System;
using System.Collections.Generic;

namespace PaperPluginUtilities
{
    public static class ApplyHelper
    {
        /// <summary>
        /// Applys a function to each item in the list, but returns that item. Note that this won't force the execute1
        /// You'll need to tack on a ".Last" or some sort of dude to get it to go.
        /// This eventually should be replaced by the stuff in Rx extensions.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="theList"></param>
        /// <param name="dothis"></param>
        /// <returns></returns>
        public static IEnumerable<T> Apply<T>(this IEnumerable<T> theList, Action<T> dothis)
        {
            foreach (var item in theList)
            {
                dothis(item);
                yield return item;
            }
        }

    }
}
